import mongoose from 'mongoose'
import UserSchema from '../schema/UserSchema.js'

// 建立模型
const model = mongoose.model('tb_user', new mongoose.Schema(UserSchema));

// 插入
function save(data) {
  return new Promise((resolve, reject) => {
    new model(data).save().then(data => {
      resolve(data);
    }).catch(err => {
      reject(err);
    })
  })
}

// 查询
function findList(data) {
  return new Promise((resolve, reject) => {
    model.find({}).then(data => {
      resolve(data);
    }).catch(err => {
      reject(err);
    })
  })
}

export default {
  save,
  findList
}
